<template>
  <div class="intelligence-situation">
    <div class="intelligence-situation__select">
      <div class="intelligence-situation__select-other">
        <el-select v-model="type" size="mini" @change="getData">
            <el-option
              v-for="(item, i) in typeList"
              :key="i"
              :label="item.laber"
              :value="item.value"
              >
            </el-option>
          </el-select>
      </div>
      <div class="intelligence-situation__select-date">
        <el-date-picker
          v-model="dayTime"
          type="month"
          :clearable="false"
          size="mini"
          value-format="yyyy-MM"
          format="yyyy年M月"
          @change="getData">
        </el-date-picker>
      </div>
    </div>
    <div class="intelligence-situation__chart">
      <ve-histogram :data="chartData" :settings="chartSettings" :extend="chartExtend" width="95%" height="13rem"></ve-histogram>
    </div>
  </div>
</template>
<script>
import echarts from 'echarts/lib/echarts'
import { getZnhqk } from 'src/api/api'
import { formatDate, formatFontSize } from 'js/utils'
import { Select, Option, DatePicker } from 'element-ui'
import Histogram from 'v-charts/lib/histogram.common'
export default {
  components: {
    [Select.name]: Select,
    [Option.name]: Option,
    [Histogram.name]: Histogram,
    [DatePicker.name]: DatePicker,
  },
  data() {
    return {
      dayTime: formatDate('yyyy-mm', new Date()),
      typeList: [
        {
          laber: '金盟管家APP使用人数',
          value: '2'
        },
        {
          laber: '金盟生活APP使用人数',
          value: '1'
        },
        {
          laber: '万联智卡使用项目数',
          value: '3'
        },
        {
          laber: '万联巡卡使用项目数',
          value: '4'
        },
        {
          laber: '智能机器人使用项目数',
          value: '5'
        },
      ],
      type: '2',
      chartSettings: {
        legend: {
          show: false
        },
      },
      chartExtend: {
        legend: {
          show: false,
        },
        tooltip: {
          show: false,
        },
        xAxis: {
          axisLabel: {
            color: '#8EC7DC',
            fontSize: formatFontSize(0.12),
          },
        },
        yAxis: {
          axisLabel: {
            color: '#fff',
            fontSize: formatFontSize(0.1),
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: '#fff',
              opacity: 0.1,
            }
          },
          splitLine: {
            show: true,
            lineStyle: {
              color: '#fff',
              opacity: 0.1,
            }
          },
          // max: 50000,
          splitNumber: 10,
        },
        grid: {  
          left: '0',  
          right: '0',
          top: '10%',
          bottom: '0',  
        },
        series: {
          barWidth: 25,
          label: { 
            show: true, 
            position: 'top',
            color: '#fff',
            fontSize: formatFontSize(0.1),
          },
          itemStyle: {
            color: new echarts.graphic.LinearGradient(
              0, 0, 0, 1,
              [
                  {offset: 0, color: 'rgba(162,127,253,0.83)'},
                  {offset: 1, color: 'rgba(66,18,188,0.2)'}
              ]
            ),
          },
        }
      },
      chartData: {
        columns: ['city', 'value'],
        rows: []
      },
    }
  },
  mounted() {
    this.getData()
  },
  methods: {
    getData() {
      const params = {
        dayTime: this.dayTime,
        type: this.type
      }
      getZnhqk(params).then(res=> {
        if(this.type === '1') {
          this.chartData.columns = ['city', 'jmshNum']
        } else if(this.type === '2') {
          this.chartData.columns = ['city', 'jmgjNum']
        } else if(this.type === '3') {
          this.chartData.columns = ['city', 'wlzkNum']
        }else if(this.type === '4') {
          this.chartData.columns = ['city', 'wlxkNum']
        }else if(this.type === '5') {
          this.chartData.columns = ['city', 'jqrNum']
        }
        this.chartData.rows = res.data
      })
    }
  },
}
</script>
<style lang="scss">
.intelligence-situation {
  padding: 10px 0px 10px;
  &__select {
    text-align: right;
    padding: 5px 20px 5px 0;
    font-size: 14px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    color: #AAECFF;
    .el-select, .el-date-editor{
      .el-input__inner {
        // width: 150px;
        border: 0;
        border-radius: 0;
        background:rgba(11,21,58,1);
        box-shadow:1px 1px 0px 0px rgba(255,255,255,0.25), 0px 2px 4px 0px rgba(0, 0, 0, 1);
        color: #AAECFF;
        font-size: 14px;
      }
      .el-input__icon {
        color: #AAECFF;
        font-size: 14px;
      }
    }
     &-date {
      margin-right: 40px;
      .el-date-editor {
        width: 135px;
      }
    }
    &-other {
      margin-right: 20px;
      .el-select {
        width: 200px;
      }
    }
    .el-checkbox {
      color: #AAECFF;
    }
    .el-checkbox__input.is-checked+.el-checkbox__label {
      color: #AAECFF;
    }
    .el-checkbox__inner {
      border-radius: 50%;
    }
  }
  &__chart {
    display: flex;
    flex-direction: column;
    align-items: center;
    // padding-top: 20px;
  }
}
</style>